Skip to content

querier: limit number of blocks queried with one store-gateway request - #16292

Merged
narqo merged 7 commits into
mainfrom
vrnkn/querier-max-blocks-per-store-request
Aug 12, 2026
Merged

querier: limit number of blocks queried with one store-gateway request#16292
narqo merged 7 commits into
mainfrom
vrnkn/querier-max-blocks-per-store-request

Conversation

@narqo

@narqo narqo commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What this PR does

The PR adds a new experimental per-tenant limit, max_blocks_per_store_request (disabled by default), that controls how many blocks a single query can request from one store-gateway instance. If a request spills over the limit, this request is split into multiple partitions, each executed concurrently against the instance.

For detailed rational see #16021

While testing the feature in a dev cell, I saw some improvement, and I believe it should be good for further testing.


Results from dev testing

Before (a request hinted 40 blocks to one store-gw instance)

Screenshot 2026-08-05 at 15 52 36

After (the same request is split into several sub-requests, hinting up to 20 blocks from a store-gw instance)

Screenshot 2026-08-05 at 18 01 34

On the store-gw side in this test, each request was bounded with up to 20 bucketBlock.ensurelndexHeaderLoaded calls per request. The total number of concurrent requests, a store-gw instance accepts is limited by store-gw's global concurrency gate.

Which issue(s) this PR fixes or relates to

Fixes #16021

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

💻 Deploy preview deleted (Mimir).

Comment thread pkg/querier/blocks_store_queryable.go Outdated
Comment thread pkg/querier/blocks_store_queryable_test.go
Comment thread pkg/querier/blocks_store_replicated_set_test.go Outdated
@narqo
narqo force-pushed the vrnkn/querier-max-blocks-per-store-request branch 4 times, most recently from 8d47850 to 821ed41 Compare August 6, 2026 09:48
@narqo
narqo marked this pull request as ready for review August 6, 2026 10:59
@narqo
narqo requested review from a team as code owners August 6, 2026 10:59

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 202e176. Configure here.

Comment thread pkg/querier/blocks_store_replicated_set.go
Comment thread pkg/querier/blocks_store_queryable.go
@narqo narqo changed the title querier: limit number of blocks pulled in one request querier: limit number of blocks queried with one store-gateway request Aug 6, 2026
Comment on lines +1058 to +1061
// Concurrently fetch series from all clients. A client may have multiple partitions; each
// partition is one independent RPC to the same store-gateway.
for c, partitions := range clients {
for _, blockIDs := range partitions {

@narqo narqo Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for the reviewers: the diffs here and below look scarier than what the changes did. We simply wrapped the loop over the list of blocks with a loop over block partitions. The body was just shifted one indentation level.

@JStickler JStickler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[docs team] Docs LGTM

@pitasi

pitasi commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

please rebase this PR on latest main, otherwise it can't merge — it's blocked on required checks that will never report.

context: #16335 changed the unit test CI matrix and the required checks got renamed (test (N, 10)test (N, 5)). CI runs from before that change only report the old names, so the branch needs to pick up the new workflow from main. sorry for the churn.

Comment thread pkg/querier/blocks_store_queryable.go Outdated
storesQueried: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "cortex_querier_storegateway_queried_total",
Help: "Total number of requests to store-gateway instances for a single query. Splitting queried blocks into partitions can produce more than one request per store-gateway instance per query.",
}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to make this a histogram? We won't get visibility at the request level with a counter. As it is, wouldn't this counter be ~the same (modulo retries) as cortex_storegateway_client_request_duration_seconds_count?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Updated in e3b5584

Comment thread pkg/util/validation/limits.go
@narqo
narqo force-pushed the vrnkn/querier-max-blocks-per-store-request branch from c9b9296 to e70e114 Compare August 12, 2026 13:44
@narqo
narqo force-pushed the vrnkn/querier-max-blocks-per-store-request branch from e70e114 to 13b4433 Compare August 12, 2026 13:46
@narqo
narqo requested a review from npazosmendez August 12, 2026 13:48
@narqo
narqo merged commit fb63699 into main Aug 12, 2026
95 checks passed
@narqo
narqo deleted the vrnkn/querier-max-blocks-per-store-request branch August 12, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Limit number of blocks that querier requests from store-gateway replication set

4 participants